package com.aquan.map_jetpack.ui.components.bottom


import androidx.activity.compose.BackHandler
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.tooling.preview.Preview
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun BottomSheetState() {

    // 弹出
    val state = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
    ///
    val scope = rememberCoroutineScope()

    ModalBottomSheetLayout(
        sheetContent = {
            Text(text = "你好哇")
        },
        sheetState = state
    ) {

        Text(text = "你好哇")

    }

    BackHandler(
        enabled = (state.currentValue == ModalBottomSheetValue.HalfExpanded ||
                state.currentValue == ModalBottomSheetValue.Expanded),
        onBack = {
            scope.launch {
                state.hide()
            }
        })
}

@Preview
@Composable
fun BottomSheetStatePreview() {
    BottomSheetState()
}

